2 #ifndef FRAMELIB_MEMORY_H 3 #define FRAMELIB_MEMORY_H 29 Pool(
void *mem,
size_t size) : mUsedRecently(
true), mTime(0), mSize(size), mPrev(NULL), mNext(NULL), mMem(mem) {}
31 bool isFree() {
return tlsf_pool_is_free(mMem); }
54 virtual void doTask() { mAllocator->addScheduledPool(); };
56 CoreAllocator *mAllocator;
72 virtual void doTask() { mAllocator->destroyScheduledPool(); };
74 CoreAllocator *mAllocator;
86 void *
alloc(
size_t size);
95 Pool *getPool(pool_t pool);
99 static Pool *createPool(
size_t size);
100 static void destroyPool(Pool *pool);
101 void linkPool(Pool *pool);
102 void unlinkPool(Pool *pool);
103 void poolToTop(Pool *pool);
104 void insertPool(Pool *pool);
105 void removePool(Pool *pool);
109 void addScheduledPool();
110 void destroyScheduledPool();
120 size_t mLastDisposedPoolSize;
123 NewThread mAllocThread;
124 FreeThread mFreeThread;
140 mAllocator->mLock.acquire();
145 mAllocator->mAllocator.prune();
146 mAllocator->mLock.release();
149 void dealloc(
void *ptr) { mAllocator->mAllocator.dealloc(ptr); }
172 void *
alloc(
size_t size);
190 CoreAllocator mAllocator;
201 static const int numLocalFreeBlocks = 16;
205 FreeBlock() : mMemory(NULL), mSize(0), mPrev(NULL), mNext(NULL) {}
229 unsigned long getSize()
const {
return mSize; }
230 const char *
getName()
const {
return mName.c_str(); }
234 void resize(
unsigned long size);
261 unsigned long mMaxSize;
262 unsigned long mCount;
276 void *
alloc(
size_t size);
302 std::vector<Storage *>::iterator findStorage(
const char *name);
306 void *removeBlock(FreeBlock *block);
312 FreeBlock mFreeLists[numLocalFreeBlocks];
315 std::vector <Storage *> mStorage;
Pruner(FrameLib_GlobalAllocator *allocator)
Definition: FrameLib_Memory.h:138
~FrameLib_LocalAllocator()
Definition: FrameLib_Memory.cpp:324
~FrameLib_GlobalAllocator()
Definition: FrameLib_Memory.h:168
double * getData() const
Definition: FrameLib_Memory.h:228
static size_t getAlignment()
Definition: FrameLib_Memory.cpp:261
Definition: FrameLib_Threading.h:124
void dealloc(void *ptr)
Definition: FrameLib_Memory.cpp:253
const char * getName() const
Definition: FrameLib_Memory.h:230
void increment()
Definition: FrameLib_Memory.h:245
void clear()
Definition: FrameLib_Memory.cpp:373
static size_t getAlignment()
Definition: FrameLib_Memory.h:285
FrameLib_LocalAllocator(FrameLib_GlobalAllocator *allocator)
Definition: FrameLib_Memory.cpp:309
void dealloc(void *ptr)
Definition: FrameLib_Memory.h:149
Definition: FrameLib_Threading.h:284
Definition: FrameLib_Threading.h:242
~Pruner()
Definition: FrameLib_Memory.h:143
void * alloc(size_t size)
Definition: FrameLib_Memory.cpp:245
Definition: FrameLib_Threading.h:179
Definition: FrameLib_Memory.h:14
static size_t alignSize(size_t x)
Definition: FrameLib_Memory.h:286
Storage * registerStorage(const char *name)
Definition: FrameLib_Memory.cpp:392
void releaseStorage(const char *name)
Definition: FrameLib_Memory.cpp:406
Definition: FrameLib_Memory.h:197
static size_t alignSize(size_t x)
Definition: FrameLib_Memory.cpp:266
Definition: FrameLib_Threading.h:179
unsigned long getSize() const
Definition: FrameLib_Memory.h:229
unsigned long decrement()
Definition: FrameLib_Memory.h:246
Definition: FrameLib_Memory.h:220
Definition: FrameLib_Memory.h:133
FrameLib_GlobalAllocator()
Definition: FrameLib_Memory.h:167